<?php
/**
 * Author Yulin
 * Email  dwzhanglong@126.com
 * Date   2017-8-31
 * Func   快3开奖期号
 */
defined('IN_YuLin') || exit('NO PERMIT!');


//江苏快3
$ckjsk3 = $db->getrow('SELECT COUNT(1) AS p FROM '.Table('lottery_k3').' WHERE tid = 1 AND day = \''.date('Ymd').'\'');
if($ckjsk3['p'] < 82)
{
	$jsk3 = strtotime(date('Y-m-d 8:30:00'));
	for($i = 1; $i < 83; $i++)
	{
		$day = date('Ymd',$jsk3);
		
		$stoptime = $jsk3 + $i * 10 * 60;
		$starttime = $stoptime - 10 * 60;
		
		$qihao = date('Ymd0',$jsk3).str_pad($i,2,0,STR_PAD_LEFT);
		
		$data['tid'] = '1';
		$data['period'] = $qihao;
		$data['starttime'] = $starttime;
		$data['stoptime'] = $stoptime;
		$data['day'] = $day;
		$data['createtime'] = time();
		$db->exec('INSERT INTO '.table('lottery_k3').''.CreateInsertSql($data));
	}
}

//安徽快3
$ckahk3 = $db->getrow('SELECT COUNT(1) AS p FROM '.Table('lottery_k3').' WHERE tid = 2 AND day = \''.date('Ymd').'\'');
if($ckahk3['p'] < 80)
{
	$ahk3 = strtotime(date('Y-m-d 8:40:00'));
	for($i = 1; $i < 81; $i++)
	{
		$day = date('Ymd',$ahk3);
		
		$stoptime = $ahk3 + $i * 10 * 60;
		$starttime = $stoptime - 10 * 60;
		
		$qihao = date('Ymd0',$ahk3).str_pad($i,2,0,STR_PAD_LEFT);
		
		$data1['tid'] = '2';
		$data1['period'] = $qihao;
		$data1['starttime'] = $starttime;
		$data1['stoptime'] = $stoptime;
		$data1['day'] = $day;
		$data1['createtime'] = time();
		$db->exec('INSERT INTO '.table('lottery_k3').''.CreateInsertSql($data1));
	}
}

//广西快3
$ckgxk3 = $db->getrow('SELECT COUNT(1) AS p FROM '.Table('lottery_k3').' WHERE tid = 3 AND day = \''.date('Ymd').'\'');
if($ckgxk3['p'] < 78)
{
	$gxk3 = strtotime(date('Y-m-d 9:28:00'));
	for($i = 1; $i < 79; $i++)
	{
		$day = date('Ymd',$gxk3);
		
		$stoptime = $gxk3 + $i * 10 * 60;
		$starttime = $stoptime - 10 * 60;
		
		$qihao = date('Ymd0',$gxk3).str_pad($i,2,0,STR_PAD_LEFT);
		
		$data['tid'] = '3';
		$data['period'] = $qihao;
		$data['starttime'] = $starttime;
		$data['stoptime'] = $stoptime;
		$data['day'] = $day;
		$data['createtime'] = time();
		$db->exec('INSERT INTO '.table('lottery_k3').''.CreateInsertSql($data));
	}
}

//湖北快3
$ckhubk3 = $db->getrow('SELECT COUNT(1) AS p FROM '.Table('lottery_k3').' WHERE tid = 4 AND day = \''.date('Ymd').'\'');
if($ckhubk3['p'] < 78)
{
	$hubk3 = strtotime(date('Y-m-d 9:00:00'));
	for($i = 1; $i < 79; $i++)
	{
		$day = date('Ymd',$hubk3);
		
		$stoptime = $hubk3 + $i * 10 * 60;
		$starttime = $stoptime - 10 * 60;
		
		$qihao = date('Ymd0',$hubk3).str_pad($i,2,0,STR_PAD_LEFT);
		$data['tid'] = '4';
		$data['period'] = $qihao;
		$data['starttime'] = $starttime;
		$data['stoptime'] = $stoptime;
		$data['day'] = $day;
		$data['createtime'] = time();
		$db->exec('INSERT INTO '.table('lottery_k3').''.CreateInsertSql($data));

	}
}

//北京快3
$ckbjk3 = $db->getrow('SELECT COUNT(1) AS p FROM '.Table('lottery_k3').' WHERE tid = 5 AND day = \''.date('Ymd').'\'');
if($ckbjk3['p'] < 89)
{
	/*$check = $db->getrow('select period from '.table('lottery_k3').' where tid = 5 order by period desc');
	if(!$check)
	{
		$arr = array();
		$arr['token'] = 'taeeaf826af0022cak';
		$arr['code'] = 'bjk3';
		$arr['rows'] = '1';
		$arr['format'] = 'json';
		$x = HttpPost('http://ho.apiplus.net/newly.do',$arr);
		$result = json_decode($x,true);
		$period = $result['data'][0]['expect'];
	}else{
		$period = $check['period'];
	}*/
	//	每天89期,106164期对应2018-04-09 09:10开奖
	//	https://www.acaicp.com/bjk3/zst/采用的是年月日期号,其他渠道用的是106164这种
	
	$bjk3 = strtotime(date('Y-m-d 9:00:00'));
	for($i = 1; $i < 90; $i++)
	{
		$day = date('Ymd',$bjk3);
		
		$stoptime = $bjk3 + $i * 10 * 60;
		$starttime = $stoptime - 10 * 60;
		
		//$qihao = $period + $i;
		$qihao = 106164 + intval(($bjk3 - strtotime('2018-04-09 09:00:00')) / 86400) * 89 + $i - 1;
		
		$data['tid'] = '5';
		$data['period'] = $qihao;
		$data['starttime'] = $starttime;
		$data['stoptime'] = $stoptime;
		$data['day'] = $day;
		$data['createtime'] = time();
		$db->exec('INSERT INTO '.table('lottery_k3').''.CreateInsertSql($data));
	}
}


//河北快3
$ckhebk3 = $db->getrow('SELECT COUNT(1) AS p FROM '.Table('lottery_k3').' WHERE tid = 6 AND day = \''.date('Ymd').'\'');
if($ckhebk3['p'] < 81)
{
	$hebk3 = strtotime(date('Y-m-d 8:30:00'));
	for($i = 1; $i < 82; $i++)
	{
		$day = date('Ymd',$hebk3);
		
		$stoptime = $hebk3 + $i * 10 * 60;
		$starttime = $stoptime - 10 * 60;
		
		$qihao = date('Ymd0',$hebk3).str_pad($i,2,0,STR_PAD_LEFT);
		
		$data['tid'] = '6';
		$data['period'] = $qihao;
		$data['starttime'] = $starttime;
		$data['stoptime'] = $stoptime;
		$data['day'] = $day;
		$data['createtime'] = time();
		$db->exec('INSERT INTO '.table('lottery_k3').''.CreateInsertSql($data));

	}
}
//甘肃快3
$ckgsk3 = $db->getrow('SELECT COUNT(1) AS p FROM '.Table('lottery_k3').' WHERE tid = 7 AND day = \''.date('Ymd').'\'');
if($ckgsk3['p'] < 72)
{
	$gsk3 = strtotime(date('Y-m-d 10:00:00'));
	for($i = 1; $i < 73; $i++)
	{
		$day = date('Ymd',$gsk3);
		
		$stoptime = $gsk3 + $i * 10 * 60;
		$starttime = $stoptime - 10 * 60;
		
		$qihao = date('Ymd0',$gsk3).str_pad($i,2,0,STR_PAD_LEFT);
		
		$data['tid'] = '7';
		$data['period'] = $qihao;
		$data['starttime'] = $starttime;
		$data['stoptime'] = $stoptime;
		$data['day'] = $day;
		$data['createtime'] = time();
		$db->exec('INSERT INTO '.table('lottery_k3').''.CreateInsertSql($data));
	}
}
//上海快3
$ckshk3 = $db->getrow('SELECT COUNT(1) AS p FROM '.Table('lottery_k3').' WHERE tid = 8 AND day = \''.date('Ymd').'\'');
if($ckshk3['p'] < 82)
{
	$shk3 = strtotime(date('Y-m-d 9:00:00'));
	for($i = 1; $i < 83; $i++)
	{
		$day = date('Ymd',$shk3);
		
		$stoptime = $shk3 + $i * 10 * 60;
		$starttime = $stoptime - 10 * 60;
		
		$qihao = date('Ymd0',$shk3).str_pad($i,2,0,STR_PAD_LEFT);
		
		$data['tid'] = '8';
		$data['period'] = $qihao;
		$data['starttime'] = $starttime;
		$data['stoptime'] = $stoptime;
		$data['day'] = $day;
		$data['createtime'] = time();
		$db->exec('INSERT INTO '.table('lottery_k3').''.CreateInsertSql($data));
	}
}

//贵州快3
$ckjlk3 = $db->getrow('SELECT COUNT(1) AS p FROM '.Table('lottery_k3').' WHERE tid = 9 AND day = \''.date('Ymd').'\'');
if($ckjlk3['p'] < 78)
{
    $jlk3 = strtotime(date('Y-m-d 8:50:00'));
    for($i = 1; $i < 79; $i++)
    {
        $day = date('Ymd',$jlk3);

        $stoptime = $jlk3 + $i * 10 * 60;
        $starttime = $stoptime - 10 * 60;

        $qihao = date('Ymd0',$jlk3).str_pad($i,2,0,STR_PAD_LEFT);

        $data['tid'] = '9';
        $data['period'] = $qihao;
        $data['starttime'] = $starttime;
        $data['stoptime'] = $stoptime;
        $data['day'] = $day;
        $data['createtime'] = time();
        $db->exec('INSERT INTO '.table('lottery_k3').''.CreateInsertSql($data));
    }
}

//吉林快3
$ckjlk3 = $db->getrow('SELECT COUNT(1) AS p FROM '.Table('lottery_k3').' WHERE tid = 10 AND day = \''.date('Ymd').'\'');
if($ckjlk3['p'] < 87)
{
	$jlk3 = strtotime(date('Y-m-d 07:35:00'));
	for($i = 1; $i < 88; $i++)
	{
		$day = date('Ymd',$jlk3);
		
		$stoptime = $jlk3 + $i * 10 * 60;
		$starttime = $stoptime - 10 * 60;
		
		$qihao = date('Ymd0',$jlk3).str_pad($i,2,0,STR_PAD_LEFT);
		
		$data['tid'] = '10';
		$data['period'] = $qihao;
		$data['starttime'] = $starttime;
		$data['stoptime'] = $stoptime;
		$data['day'] = $day;
		$data['createtime'] = time();
		$db->exec('INSERT INTO '.table('lottery_k3').''.CreateInsertSql($data));
	}
}

// 大富快3
$ckjlk3 = $db->getrow('SELECT COUNT(1) AS p FROM '.Table('lottery_k3').' WHERE tid = 20 AND day = \''.date('Ymd').'\'');
if($ckjlk3['p'] < 1410)
{
    $dfk3 = strtotime(date('Ymd'));
    for($i = 1; $i < 1411; $i++)
    {
        $day = date('Ymd',$dfk3);

        $stoptime = $dfk3 + $i * 1 * 60;
        $starttime = $stoptime - 1 * 60;

        $qihao = date('ymd',$dfk3).str_pad($i,4,0,STR_PAD_LEFT);

        $data['tid'] = '20';
        $data['period'] = $qihao;
        $data['starttime'] = $starttime;
        $data['stoptime'] = $stoptime;
        $data['day'] = $day;
        $data['createtime'] = time();
        $db->exec('INSERT INTO '.table('lottery_k3').''.CreateInsertSql($data));
    }
}
